# -*- coding: utf-8 -*-
from api.base_api.base_api import BaseApi
import random

class SelectCar(BaseApi):
    make_list_url = "http://192.168.1.141:8001/car-estimate/make-list"
    model_list_url = "http://192.168.1.141:8001/car-estimate/model-list/make_id"
    style_list_url = 'http://192.168.1.141:8001/car-estimate/style-list/model_id'

    def select_car(self):

        payload = {

        }

        # 车辆品牌
        make_list_response = self.get(self.make_list_url, payload)
        index = random.randint(0,len(make_list_response.json())-1)
        carBrand = make_list_response.json()[index]['Name']
        makeId = make_list_response.json()[index]['MakeId']

        #车辆型号
        new_model_list_url =self.model_list_url.replace("make_id", str(makeId))
        model_list_response = self.get(new_model_list_url, payload)
        index = random.randint(0,len(model_list_response.json())-1)
        carSeries = model_list_response.json()[index]['Text']
        carSeriesvalue = model_list_response.json()[index]['Value']

        #车系
        new_style_list_url = self.style_list_url.replace("model_id", str(carSeriesvalue))
        style_list_response = self.get(new_style_list_url, payload)
        index = random.randint(0, len(style_list_response.json()) - 1)
        text = style_list_response.json()[index]['Text']
        groupName = style_list_response.json()[index]['GroupName']
        carType = groupName + text
        carTypeValue = style_list_response.json()[index]['Value']
        return carBrand,carSeries,carType,carTypeValue

